#!/bin/bash
mkdir encode -p;
for f in *.mkv; do
#x264
 ffmpeg -i "$f" -c copy -level 4.0 -c:v libx264 -x264-params bframes=8:psy-rd=0.8:aq-mode=3:aq-strength=0.8:deblock=-1,-1:me=umh:merange=32:qcomp=0.68 -b_strategy 2 -preset veryslow -crf 18 -sn -colorspace:v 'bt709' -color_primaries:v 'bt709' -color_trc:v 'bt709' -color_range:v 'tv' -metadata:s:v:0 title="extonan.id" -c:a aac -b:a 128k -y -f matroska "encode/${f%.mkv}-1080p.mkv"
 ffmpeg -i "$f" -c copy -s 1280x720 -level 4.0 -c:v libx264 -x264-params bframes=8:psy-rd=0.6:aq-mode=3:aq-strength=0.8:deblock=-1,-1:me=umh:merange=32:qcomp=0.68 -b_strategy 2 -preset veryslow -crf 18 -sn -colorspace:v 'bt709' -color_primaries:v 'bt709' -color_trc:v 'bt709' -color_range:v 'tv' -metadata:s:v:0 title="extonan.id" -c:a aac -b:a 128k -y -f matroska "encode/${f%.mkv}-720p.mkv"
#x265
 ffmpeg -i "$f" -c copy -c:v libx265 -x265-params bframes=8:psy-rd=1:aq-mode=3:aq-strength=0.8:deblock=1,1 -preset slow -crf 20 -pix_fmt yuv420p10le -sn -colorspace:v 'bt709' -color_primaries:v 'bt709' -color_trc:v 'bt709' -color_range:v 'tv' -metadata:s:v:0 title="extonan.id" -c:a aac -b:a 128k -y -f matroska "encode/${f%.mkv}-1080p-x265.mkv"
 ffmpeg -i "$f" -c copy -s 1280x720 -c:v libx265 -x265-params bframes=8:psy-rd=1:aq-mode=3:aq-strength=0.8:deblock=1,1 -preset slow -crf 20 -pix_fmt yuv420p10le -sn -colorspace:v 'bt709' -color_primaries:v 'bt709' -color_trc:v 'bt709' -color_range:v 'tv' -metadata:s:v:0 title="extonan.id" -c:a aac -b:a 128k -y -f matroska "encode/${f%.mkv}-720p-x265.mkv"
done
